package com.boot2523.control;

import com.boot2523.bean.Admin;
import com.boot2523.service.AdmiS;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "admin")
public class AdminC {
    @Resource
    public AdmiS as;
    @GetMapping(value = "/one")
    public Map<String,Object> one(HttpSession session, Admin a){
        //查询数据库
        Admin b=as.one(a.getAname(),a.getApwd());
        //有数据时存入session
        Map<String,Object> data=new HashMap<>();
        if (b.getAid()>0){
            //将结果存入session中
            session.setAttribute("aid",a.getAid());
            session.setAttribute("aname",a.getAname());
            data.put("r",1);
            data.put("ad",a);
        }else{
            data.put("r",0);
            data.put("ad",null);
        }
        return data;
    }
}
